package hs.framework.opcClient.aop.logger;

import lombok.extern.log4j.Log4j2;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * @Description TODO
 * @Author sxmz
 * @Date 2021/5/12 0012 下午 4:17
 */
@Aspect
@Order(5)
@Component
public class LogAspect {
    private long startTime;
    private static Logger log = LoggerFactory.getLogger(LogAspect.class);
//    @Pointcut("execution(public * hs.framework.opcClient..service..*(..))")
    @Pointcut("execution(public * hs.framework.opcClient.utils.*.*(..))")
    public void logPointcut() {
    }

    @Before("logPointcut()")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        startTime = System.currentTimeMillis();

        String methodName = joinPoint.getSignature().getName();

        // 记录下请求内容
        log.info("准备执行 " + methodName + " 方法");
        System.out.println("hello,这里是aop监听，当前执行方法为："+methodName);
    }
}
